<template>
  <div class="flexContent">
    <div class="searchBox">
      <!-- 要货单记录 -->
      <el-form class="demo-form-inline" label-position="left" label-width="auto">
        <div class="serFlexBox">
          <div class="inputBox">
            <el-row :gutter="12" style="display: flex;flex-wrap: wrap;">
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="门店名称">
                  <el-select v-model="sForm.storeId" clearable style="width: 95%" popper-class="eloption"
                    placeholder="请选择门店" filterable @click.native="getShopEasy">
                    <el-option v-for="shop in shopLists" :key="shop.id" :value="shop.id" :label="shop.name" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="要货单编号">
                  <el-input v-clearEmoji v-model.trim="sForm.requireNumber" clearable style="width: 95%"
                    placeholder="请输入要货单编号" @keyup.enter.native="searchFn" />
                </el-form-item>
              </el-col>
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="点采编号">
                  <el-input v-clearEmoji v-model.trim="sForm.pickNumber" placeholder="请输入点采编号" clearable
                    style="width: 95%" @keyup.enter.native="searchFn" />
                </el-form-item>
              </el-col>
              <el-col :xs="12" :sm="12" :md="12" :lg="10" :xl="6">
                <el-form-item label="分录时间">
                  <el-date-picker clearable v-model="date" style="width: 95%" type="daterange" unlink-panels
                    range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div class="btnBox">
            <el-button @click.stop="searchFn" class="searchBtn" icon="el-icon-search">搜索</el-button>
            <el-button @click.stop="resetFn" class="resetBtn" icon="el-icon-refresh-right">重置</el-button>
          </div>
        </div>
      </el-form>
    </div>
    <div class="table" id="tableBox" v-height>
      <div style="flex:1;">
        <vxe-table :column-config="{ resizable: true }" border class="tablebox" ref="xTable1"
          :row-config="{ isHover: true }" :scroll-y="{ enabled: true, gt: 21 }" align="center" height="100%"
          size="medium">
          <vxe-column type="seq" width="80" title="序号" />
          <vxe-column field="warehouseName" title="仓库名称"
            :min-width="elTableAdaptationWidth('warehouseName', memberList)" />
          <vxe-column field="pickNumber" title="点采编号" :min-width="elTableAdaptationWidth('pickNumber', memberList)" />
          <vxe-column field="requireNumber" title="要货单编号"
            :min-width="elTableAdaptationWidth('requireNumber', memberList)" />
          <vxe-column field="storeNumber" title="门店编号" :min-width="elTableAdaptationWidth('storeNumber', memberList)" />
          <vxe-column field="storeName" title="门店名称" :min-width="elTableAdaptationWidth('storeName', memberList)" />
          <vxe-column field="entryTime" title="分录时间" min-width="150">
            <template v-slot="{ row }">
              <span>{{ row.entryTime | parseTime }}</span>
            </template>
          </vxe-column>
          <vxe-column title="操作" v-if="$showFn(['toorderinfo_detail'])" fixed="right" width="100">
            <template v-slot="{ row }">
              <el-button type="text" style="margin-right: 10px; color: rgb(0, 132, 255)" @click.stop="entryDetail(row)"
                v-has="'toorderinfo_detail'">详情</el-button>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
      <div class="paginationBox">
        <el-pagination :current-page="page.pageNum" background :page-sizes="$pageSizes" :page-size="page.pageSize"
          layout="total,->, sizes, prev, pager, next, jumper" :total="page.total" @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </div>
  </div>
</template>

<script>
import { getShopEasy } from "@/api/shop";
import { getStoreRequireList } from "@/api/entrycenter";
export default {
  name: "ToOrderInfo",
  data() {
    return {
      name: "",
      shopLists: [],
      sForm: {
        storeId: "",
        endTime: "",
        openTime: "",
        requireNumber: "",
        pickNumber: "",
      },
      date: [],
      isSearch: false,
      dateList: {},
      memberList: [],
      page: {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      },
    };
  },
  created() {
    // this.getShopEasy();
    this.getStoreRequireList();
  },
  methods: {
    async getShopEasy() {
      const res = await getShopEasy();
      if (res.code === 200) {
        this.shopLists = res.data.store;
        console.log(res);
      }
    },
    async getStoreRequireList() {
      if (!this.isSearch) {
        this.sForm = {
          storeId: "",
          endTime: "",
          openTime: "",
          requireNumber: "",
          pickNumber: "",
        };
      }
      const res = await getStoreRequireList({ ...this.page, ...this.sForm });
      if (res.code === 200) {
        console.log(res);
        this.memberList = res.data.list;
        this.page.pageSize = res.data.pageSize;
        this.page.pages = res.data.pages;
        this.page.pageNum = res.data.pageNum;
        this.page.total = res.data.total;
        const $table = this.$refs.xTable1
        $table.loadData(this.memberList);
      }
      console.log(res, "订单");
    },
    async searchFn() {
      this.page = {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      };

      this.isSearch = true;
      this.sForm.endTime = this.date?.length ? this.date[1] : "";
      this.sForm.openTime = this.date?.length ? this.date[0] : "";
      this.getStoreRequireList();
    },
    resetFn() {
      this.page = {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      };
      this.isSearch = false;
      this.date = [];
      this.sForm = {
        storeId: "",
        endTime: "",
        openTime: "",
        requireNumber: "",
        pickNumber: "",
      };
      this.getStoreRequireList();
    },
    // 获取条数改变
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.page.pageNum = 1;
      console.log(`每页 ${val} 条`);
      this.getStoreRequireList();
    },
    // 获取页数改变
    handleCurrentChange(val) {
      this.page.pageNum = val;
      this.getStoreRequireList();
    },
    entryDetail(row) {
      // this.$router.push('toOrderDetail')
      this.$router.push({
        path: "toOrderDetail",
        query: {
          id: row.id,
        },
      });
    },
  },
};
</script>

<style scoped lang="scss"></style>
